home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / AfterDark / TwilightZone ƒ / source / windowstuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  4.1 KB  |  222 lines  |  [TEXT/KAHL]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * Simple Sample Application Framework
  4.  *
  5.  * ©1991 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * windowstuff.c -- window class instantiation/dispatching
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        11/7/91        1.0d1        initial coding
  14.  *
  15.  */
  16.  
  17. #include "const.h"
  18. #include "mytypes.h"
  19. #include "globals.h"
  20. #include "utils.h"
  21.  
  22. #include "base.window.h"
  23. #include "dimmer.window.h"
  24.  
  25. #include "windowstuff.h"
  26.  
  27. /* gets info handle for a window */
  28.  
  29. TInfoHndl GetWindowInfo(WindowPtr window)
  30. {
  31.     TInfoHndl theInfo;
  32.     
  33.     if (window==nil)
  34.         return nil;
  35.         
  36.     theInfo = (TInfoHndl) GetWRefCon(window);
  37.     return theInfo;
  38. }
  39.  
  40.  
  41. /* sets info handle for a window */
  42.  
  43. void SetWindowInfo(WindowPtr window,TInfoHndl info)
  44. {
  45.     if (window==nil) {
  46.         DoError(kInternalError);
  47.         return;
  48.     }
  49.         
  50.     SetWRefCon (window,(long)info);
  51. }
  52.  
  53.  
  54. /* gets window kind of a given window */
  55.  
  56. WindowKind GetWindowKind(WindowPtr window)
  57. {
  58.     WindowKind wKind;
  59.     
  60.     if (window==nil) {
  61.         DoError(kInternalError);
  62.         return;
  63.     }
  64.     wKind = ((WindowPeek)window)->windowKind;
  65.     return wKind;
  66. }
  67.  
  68.  
  69. /* sets window kind of a given window */
  70.  
  71. void SetWindowKind(WindowPtr window,WindowKind wKind)
  72. {
  73.     if (window==nil) {
  74.         DoError(kInternalError);
  75.         return;
  76.     }
  77.  
  78.     wKind += kWindowKindOffset;
  79.     ((WindowPeek)window)->windowKind = wKind;
  80. }
  81.  
  82.  
  83. /* checks to see if a window is of a certain type */
  84.  
  85. Boolean IsWindowType(WindowPtr window,WindowKind type)
  86. {
  87.     return (type == GetWindowKind(window));
  88. }
  89.  
  90.  
  91. /* returns true if it's a window created by the application */
  92.  
  93. Boolean IsAppWindow(WindowPtr window)
  94. {
  95.     WindowKind wKind;
  96.     
  97.     if (!window)
  98.         return false;
  99.     
  100.     wKind = GetWindowKind(window);
  101.     return (wKind >= userKind);
  102. }
  103.  
  104.  
  105. /* returns true if the window belongs to a DA */
  106.  
  107. Boolean IsDAWindow(WindowPtr window)
  108. {
  109.     return (GetWindowKind(window) < 0);
  110. }
  111.  
  112.  
  113. /* makes a window of a given type and returns its window pointer */
  114.  
  115. WindowPtr MakeWindow(WindowKind windowClass,Rect *wRect,StringPtr title,Boolean visible)
  116. {
  117.     WindowPtr window;
  118.     Rect theRect = kDefaultWindowRect;
  119.     
  120.     if (wRect!=nil)
  121.         theRect = *wRect;
  122.         
  123.     switch (windowClass) {
  124.         case kBaseWindow:
  125.             window = BaseMakeWindow(&theRect,title,visible,documentProc,true);
  126.             break;
  127.         case kDimmerWindow:
  128.             window = DimmerMakeWindow(&theRect,title,visible,8,true);
  129.             break;
  130.         default:
  131.             DoError(kInternalError);
  132.     }
  133.     
  134.     return window;
  135. }
  136.  
  137.  
  138. /* sends a message to a given window */
  139.  
  140. void *SendWindowMessage(WindowPtr window,short msg,void *data)
  141. {
  142.     TInfoHndl infoHndl;
  143.     char hState;
  144.     MsgProc callProc;
  145.     void *theMsg;
  146.     
  147.     if (!IsAppWindow(window))
  148.         return nil;
  149.     
  150.     infoHndl = GetWindowInfo(window);
  151.     hState = HGetState((Handle)infoHndl);
  152.     HLock((Handle)infoHndl);
  153.     
  154.     switch (msg) {
  155.         case kIdleMessage:
  156.             callProc = (**infoHndl).m_idle;
  157.             break;
  158.         case kFixCursorMessage:
  159.             callProc = (**infoHndl).m_fixCursor;
  160.             break;
  161.         case kActivateMessage:
  162.             callProc = (**infoHndl).m_activate;
  163.             break;
  164.         case kDeactivateMessage:
  165.             callProc = (**infoHndl).m_deactivate;
  166.             break;
  167.         case kUpdateMessage:
  168.             callProc = (**infoHndl).m_update;
  169.             break;
  170.         case kKeyMessage:
  171.             callProc = (**infoHndl).m_key;
  172.             break;
  173.         case kResizeMessage:
  174.             callProc = (**infoHndl).m_resize;
  175.             break;
  176.         case kClickMessage:
  177.             callProc = (**infoHndl).m_click;
  178.             break;
  179.         case kDestroyMessage:
  180.             callProc = (**infoHndl).m_destroy;
  181.             break;
  182.         case kUndoMessage:
  183.             callProc = (**infoHndl).m_undo;
  184.             break;
  185.         case kCutMessage:
  186.             callProc = (**infoHndl).m_cut;
  187.             break;
  188.         case kCopyMessage:
  189.             callProc = (**infoHndl).m_copy;
  190.             break;
  191.         case kPasteMessage:
  192.             callProc = (**infoHndl).m_paste;
  193.             break;
  194.         case kClearMessage:
  195.             callProc = (**infoHndl).m_clear;
  196.             break;
  197.         case kPrintMessage:
  198.             callProc = (**infoHndl).m_print;
  199.             break;
  200.         case kPageSetupMessage:
  201.             callProc = (**infoHndl).m_pageSetup;
  202.             break;
  203.         case kSaveMessage:
  204.             callProc = (**infoHndl).m_save;
  205.             break;
  206.         case kLoadMessage:
  207.             callProc = (**infoHndl).m_load;
  208.             break;
  209.         case kEventMessage:
  210.             callProc = (**infoHndl).m_event;
  211.             break;
  212.         default:
  213.             return;
  214.     }
  215.     
  216.     if (callProc)
  217.         theMsg = (*callProc)(window,*infoHndl,data);
  218.     
  219.     HSetState((Handle)infoHndl,hState);
  220.     return theMsg;
  221. }
  222.